<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="手牌号" prop="handBrand">
        <el-input
          v-model="queryParams.handBrand"
          placeholder="请输入手牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">F1读牌</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:details:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:details:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:details:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:details:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
-->

    <div class="big_box">
      <div class="left_box">
        <el-card class="box-card" shadow="hover" >
          <div class="mx_box" >
            <el-tabs v-model="activeName" @tab-click="handleClick" >
              <div>
                <p style="color: #00afff;font-size: 18px;">手牌消费记录</p>
                  <el-table v-loading="loading" :data="detailsList" @selection-change="handleSelectionChange" border >
                    <el-table-column label="手牌号" align="center" prop="handBrand" />
                    <el-table-column label="项目名称" align="center" prop="entryName" />
                    <el-table-column label="项目类别" align="center" prop="projectCategory">
                      <template slot-scope="scope">
                        <dict-tag :options="dict.type.yqg_project_category" :value="scope.row.projectCategory"/>
                      </template>
                    </el-table-column>
                    <el-table-column label="项目代码" align="center" prop="projectCode" />
                    <el-table-column label="助记码" align="center" prop="mnemonicCode" />
                    <el-table-column label="单位" align="center" prop="unit" />
                    <el-table-column label="单价" align="center" prop="unitPrice" />
<!--                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                      <template slot-scope="scope">
                        <el-button
                          size="mini"
                          type="text"
                          icon="el-icon-edit"
                          @click="handleUpdate(scope.row)"
                          v-hasPermi="['project:details:edit']"
                        >修改</el-button>
                        <el-button
                          size="mini"
                          type="text"
                          icon="el-icon-delete"
                          @click="handleDelete(scope.row)"
                          v-hasPermi="['project:details:remove']"
                        >删除</el-button>
                      </template>
                    </el-table-column>-->
                  </el-table>
                </div>
              </el-tabs>
            </div>
        </el-card>
      </div>

      <br>

      <div class="br"> </div>
      <div class="right_box">
        <el-card class="box-card" shadow="hover" >
          <div class="mx_box" >
            <el-tabs v-model="activeName" @tab-click="handleClick" >
              <div>
                <p style="color: #00afff;font-size: 18px;">留牌手牌消费记录</p>
                <el-table v-loading="loading" :data="detailsList2" @selection-change="handleSelectionChange" border>
<!--                  <el-table-column type="selection" width="55" align="center" />-->
                  <el-table-column label="手牌号" align="center" prop="handBrand" />
                  <el-table-column label="项目名称" align="center" prop="entryName" />
                  <el-table-column label="项目类别" align="center" prop="projectCategory">
                    <template slot-scope="scope">
                      <dict-tag :options="dict.type.yqg_project_category" :value="scope.row.projectCategory"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="项目代码" align="center" prop="projectCode" />
                  <el-table-column label="助记码" align="center" prop="mnemonicCode" />
                  <el-table-column label="单位" align="center" prop="unit" />
                  <el-table-column label="单价" align="center" prop="unitPrice" />
<!--                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['project:details:edit']"
                      >修改</el-button>
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-delete"
                        @click="handleDelete(scope.row)"
                        v-hasPermi="['project:details:remove']"
                      >删除</el-button>
                    </template>
                  </el-table-column>-->
                </el-table>
              </div>

              <br>
              <div >
                <el-row :gutter="10" class="mb8">
                  <el-col :span="1.5">
                    <el-button
                      type="primary"
                      plain
                      @click="handleTransfer"
                      v-hasPermi="['lck:equipment:add']"
                    >F3留牌</el-button>
                  </el-col>
                </el-row>
              </div>
            </el-tabs>
          </div>
        </el-card>
      </div>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改消费详细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="手牌号" prop="handBrand">
          <el-input v-model="form.handBrand" placeholder="请输入手牌号" />
        </el-form-item>
        <el-form-item label="手牌类别" prop="handCategory">
          <el-select v-model="form.handCategory" placeholder="请选择手牌类别">
            <el-option
              v-for="dict in dict.type.yqg_hand_category"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手牌状态" prop="handState">
          <el-select v-model="form.handState" placeholder="请选择手牌状态">
            <el-option
              v-for="dict in dict.type.yqg_hand_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="留牌状态" prop="retentionStatus">
          <el-select v-model="form.retentionStatus" placeholder="请选择留牌状态">
            <el-option
              v-for="dict in dict.type.yqg_retention_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="并牌状态" prop="mergeStatus">
          <el-select v-model="form.mergeStatus" placeholder="请选择并牌状态">
            <el-option
              v-for="dict in dict.type.yqg_merge_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="项目名称" prop="entryName">
          <el-input v-model="form.entryName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目类别" prop="projectCategory">
          <el-select v-model="form.projectCategory" placeholder="请选择项目类别">
            <el-option
              v-for="dict in dict.type.yqg_project_category"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目代码" prop="projectCode">
          <el-input v-model="form.projectCode" placeholder="请输入项目代码" />
        </el-form-item>
        <el-form-item label="助记码" prop="mnemonicCode">
          <el-input v-model="form.mnemonicCode" placeholder="请输入助记码" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="单价" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetails, getDetails, delDetails, addDetails, updateDetails } from "@/api/project/details";

export default {
  name: "Details",
  dicts: ['yqg_hand_category', 'yqg_hand_state', 'yqg_payment_method', 'yqg_consumption_status', 'yqg_retention_status', 'yqg_project_category', 'yqg_post', 'yqg_check_out_status', 'yqg_department', 'yqg_merge_status', 'yqg_sailings_signs', 'yqg_next_clock_status'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 消费详细表格数据
      detailsList: [],
      detailsList2: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        deptId: null,
        department: null,
        nickName: null,
        userName: null,
        post: null,
        handBrand: null,
        handCategory: null,
        handState: null,
        retentionStatus: null,
        mergeStatus: null,
        openingTime: null,
        drawTime: null,
        mergeHands: null,
        mergeBarBillsId: null,
        leaveTime: null,
        beforeLeave: null,
        beforeBarBillsId: null,
        entryName: null,
        projectCategory: null,
        projectCode: null,
        mnemonicCode: null,
        unit: null,
        unitPrice: null,
        commissionPrice: null,
        together: null,
        sailingsSigns: null,
        barBillsId: null,
        recordingTime: null,
        quantity: null,
        totalAmount: null,
        seat: null,
        orderNumber: null,
        paymentMethod: null,
        consumptionStatus: null,
        chargebackTime: null,
        reasonForChargeback: null,
        chargebackProcessorAccount: null,
        chargebackProcessorName: null,
        clockTime: null,
        nextClockTime: null,
        nextClockStatus: null,
        recordEmployeeNumber: null,
        recorderEmployeeName: null,
        roomType: null,
        openingHours: null,
        checkOutTime: null,
        checkOutStatus: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询消费详细列表 */
    getList() {
      /*this.loading = true;*/
      listDetails(this.queryParams).then(response => {
        if((this.loading==true)&&(this.queryParams.handBrand != null)) {
          this.detailsList = response.rows;
          this.total = response.total;
        }
        this.loading = false;
      });


      this.queryParams.handBrand = "002";
      listDetails(this.queryParams).then(response => {
        this.queryParams.handBrand = null;
        this.queryParams.pageNum = 1;
        this.detailsList2 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        deptId: null,
        department: null,
        nickName: null,
        userName: null,
        post: null,
        handBrand: null,
        handCategory: null,
        handState: null,
        retentionStatus: null,
        mergeStatus: null,
        openingTime: null,
        drawTime: null,
        mergeHands: null,
        mergeBarBillsId: null,
        leaveTime: null,
        beforeLeave: null,
        beforeBarBillsId: null,
        entryName: null,
        projectCategory: null,
        projectCode: null,
        mnemonicCode: null,
        unit: null,
        unitPrice: null,
        commissionPrice: null,
        together: null,
        sailingsSigns: null,
        barBillsId: null,
        recordingTime: null,
        quantity: null,
        totalAmount: null,
        seat: null,
        orderNumber: null,
        paymentMethod: null,
        consumptionStatus: null,
        chargebackTime: null,
        reasonForChargeback: null,
        chargebackProcessorAccount: null,
        chargebackProcessorName: null,
        clockTime: null,
        nextClockTime: null,
        nextClockStatus: null,
        recordEmployeeNumber: null,
        recorderEmployeeName: null,
        roomType: null,
        openingHours: null,
        checkOutTime: null,
        checkOutStatus: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.loading=true;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加消费详细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.id || this.ids
      getDetails(ID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改消费详细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetails(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetails(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids;
      this.$modal.confirm('是否确认删除消费详细编号为"' + IDs + '"的数据项？').then(function() {
        return delDetails(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/details/export', {
        ...this.queryParams
      }, `details_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>

.big_box{height: 60%;display: flex;}
.left_box{width: 44%;height: 600px;}
.right_box{width: 44%;height: 600px;}
.button{width: 145px;height: 50px;}
.mx_box{height: 600px;margin: auto}
.x_box{height: 40%;}
.br{width: 2%;height: 600px;}

</style>
